package com.hmyuan.util;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
	/**
     * 把日期字符串格式化成日期类型
     */
    public static Date stringToDate(String dateStr, String format) {  
        SimpleDateFormat simple = new SimpleDateFormat(format); 
        try {  
            simple.setLenient(false);  
            return simple.parse(dateStr);  
        } catch (Exception e) {  
            return  null;  
        }  
     }  
    
    
    /**
     * 把日期类型格式化成字符串
     */
    public static String dateToString(Date date, String format) {
        SimpleDateFormat formater = new SimpleDateFormat(format);
        try {
            return formater.format(date);
        } catch (Exception e) {
            return null;
        }
    }
    /**
     * 获取时间戳
     */
    public static long getTimestamp()
    {
        return System.currentTimeMillis();
    }
}
